package priv.ln.one;

import java.util.Scanner;

/**
 * ClassName: exer2
 * Package: priv.ln.one
 * Description:从键盘读入学生成绩，找出最高分，并输出学生成绩等级。
 *              成绩>=最高分-10  等级为’A’
 *              成绩>=最高分-20  等级为’B’
 *              成绩>=最高分-30  等级为’C’
 *              其余            等级为’D’
 *        提示：先读入学生人数，根据人数创建int数组，存放学生成绩。
 *
 * @Author 辣辣
 * @Create 2024/6/12 19:16
 * @Version 1.0
 */
public class exer2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入学生人数：");
        int studentNumber = sc.nextInt();//记录学生人数

        int[] score = new int[studentNumber];//记录分数
        System.out.println("请输入" + studentNumber + "个成绩:");
        int maxScore = 0;//记录最高分,优化int maxScore = score[0];

        for (int i = 0; i < studentNumber; i++) {
            score[i] = sc.nextInt();

            if(maxScore < score[i]){//获取最高分
                maxScore = score[i];
            }

        }
        System.out.println("最高分是：" + maxScore);

        //判断等级
        for (int i = 0; i < studentNumber; i++) {
            if (score[i] >= maxScore - 10) {
                System.out.println("student " + i + " score is " + score[i] + " grade is A");
            } else if (score[i] >= maxScore - 20) {
                System.out.println("student " + i + " score is " + score[i] + " grade is B");
            } else if (score[i] >= maxScore - 30) {
                System.out.println("student " + i + " score is " + score[i] + " grade is C");
            } else {
                System.out.println("student " + i + " score is " + score[i] + " grade is D");
            }
        }

        /*
        char grade;
        for (int j = 0; j < studentNumber; j++) {
            if (score[j] >= maxScore - 10) {
                grade = 'A';
            } else if (score[j] >= maxScore - 20) {
                grade = 'B';
            } else if (score[j] >= maxScore - 30) {
                grade = 'C';
            } else {
                grade = 'D';
            }
            System.out.println("student " + j + " score is " + score[j] + " grade is " + grade);
        }
        */

        sc.close();
    }
}
